package com.xiaoyin.community.Controller;

import com.xiaoyin.community.Domain.SolrDataDomain;
import com.xiaoyin.community.Service.SolrService;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.SolrDocumentList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.solr.core.mapping.SolrDocument;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yinjianping@baidu.com on 2018/7/24.
 *
 * @Description:
 * @Modified By:
 */
@RestController
public class SolrController {
    @Autowired
    private SolrService solrService;

    @GetMapping(value = "/solr/{name}")
    public SolrDocumentList query(@PathVariable("name") String name)throws IOException,SolrServerException{
        return solrService.query(name,1,10);
//        SolrDocumentList documents = solrService.query(name,1,10);
//        List<SolrDataDomain> list = new ArrayList<SolrDataDomain>();
//        for (org.apache.solr.common.SolrDocument document:documents
//             ) {
//            SolrDataDomain solrDataDomain = new SolrDataDomain();
//            solrDataDomain.setCandicate_id(Integer.valueOf(document.getFieldValue("candicate_id").toString()));
//            solrDataDomain.setCandicate_name(document.getFieldValue("candicate_name").toString());
//            solrDataDomain.setCandicate_class(document.getFieldValue("candicate_class").toString());
//            solrDataDomain.setCandicate_phone(document.getFieldValue("candicate_phone").toString());
//
//            list.add(solrDataDomain);
//        }
//        return list;
    }
}
